<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class MLogger
{
    private static $_instance=null;
    private $_logger;
    const LEVEL_TRACE       = 'trace';
    const LEVEL_WARNING     = 'warning';
    const LEVEL_ERROR       = 'error';
    const LEVEL_INFO        = 'info';
    const LEVEL_PROFILE     = 'profile';

    
    private function __construct() {
        Logger :: configure(dirname(__FILE__) . '/../log4php/log4php.properties');
        $this->_logger = Logger :: getLogger('log');
    }

    
    static public function getInstance() {
        if (is_null(self::$_instance) || !isset(self::$_instance)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    
    private function format_time($message) {
                date_default_timezone_set('Asia/Shanghai');
        return date( "Y-m-d H:i:s    ") . $message;
    }

    
    public function trace($message, $category='application') {
        $message = $this->format_time($message);
        $this->_logger->debug($message);
    }


    
    public function info($message, $category='application') {
        $message = $this->format_time($message);
        $this->_logger->info($message);
    }

    
    public function warn($message, $category='application') {
        $message = $this->format_time($message);
        $this->_logger->warn($message);
    }

    
    public function error($message, $category='application') {
        $message = $this->format_time($message);
        $this->_logger->error($message);
    }

}
?>